const app = getApp();
Page({
  data:{
    banklist:[]
  },
  onLoad:function(options){
    if(options.from == 'change'){
      this.setData({
        fromwhere:'change'
      })
    }else{
      this.setData({
        fromwhere: 'add'
      })
    }
    const _this = this;
    wx.request({
      url: app.globalData.path + 'services/app/applets/GetBankList',
      data: {
        "bankCode": ""
      },
      method: 'POST',
      header: {
        'content-type': 'application/json', // 默认值
        'Authorization': 'Bearer ' + app.globalData.authorization
      },
      success: function (res) {
        console.log(res.data);
        if(res.data.success){
          _this.setData({
            banklist:res.data.result.items
          })
        } else {
          wx.showToast({
            title: res.data.error.message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  // 设置银行卡
  setbank:function(e){
    console.log(e.currentTarget.id)
    console.log(e.currentTarget.dataset.id)
    if(this.data.fromwhere=='change'){
      // wx.navigateTo({
      //   url: '../changecard/changecard?bankName=' + e.currentTarget.id,
      // })
      wx.setStorage({
        key: 'banks',
        data: {
          bankName: e.currentTarget.dataset.id,
          bankId: e.currentTarget.id
        }
      })
      wx.navigateBack()
    }else{
      // wx.navigateTo({
      //   url: '../addcard/addcard?bankName=' + e.currentTarget.id,
      // })
      wx.setStorage({
        key: 'banks',
        data: {
          bankName: e.currentTarget.dataset.id,
          bankId: e.currentTarget.id
        }
      })
      wx.navigateBack()
    }
  }
})